package jjn.round2;

/**
 * @author Jiang Jining
 * @since 2023-06-07 21:57
 */
public class LeetCode80_RemoveDuplicatesFromSortedArrayII {
    public int removeDuplicates(int[] nums) {
        return process(nums, 2);
    }
    
    int process(int[] nums, int k) {
        int u = 0;
        // nums有序
        for (int x : nums) {
            // 仅需要跟前k位的数字比较即可
            if (u < k || nums[u - k] != x) {
                nums[u++] = x;
            }
        }
        return u;
    }
    
}
